package edu.stu.software.family.client;

import java.io.InputStream;
import java.net.Socket;
import java.util.Scanner;

import edu.stu.software.family.RabbitMQ.MQSend;
import edu.stu.software.family.file.reader.FileNioReader;

public class ClientSocket {
	/**
	 * 
	 * @author huang_gong_liang
	 *
	 */
    @SuppressWarnings("resource")
	public static void main(String[] args) throws Exception {

        Socket socket = new Socket("localhost", 8899);
        //读取文件内容,发送到消息队列中
        System.out.println("please input your file:");
        String filePath = new Scanner(System.in).next();
        //创建输入流读取客户端处理消息队列的信息
        String read = FileNioReader.read("F:\\file\\"+filePath);
        MQSend.sendMsg(read); 
        //创建输入流读取客户端处理消息队列的信息 
        InputStream is = socket.getInputStream();
        byte[] bytes = new byte[1024];
        int len;
        while ((len = is.read(bytes)) != -1){
            System.out.println(new String(bytes,0,len));
        }
        MQSend.sendMsg(read);
        is.close();
        socket.close();

    }
}
